package com.pocket.demo.core.mq.rabbitMQ.demo;

import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.UUID;

/**
 * @author cookie.
 **/
public class FanoutPublisher {

    private static final Logger LOGGER = LoggerFactory.getLogger(FanoutPublisher.class);

    @Resource
    private RabbitMessagingTemplate rabbitMessagingTemplate;

    @Scheduled(cron = "*/5 * * * * *")
    public void sendErrorMessage()
    {
        String message = UUID.randomUUID().toString();
        LOGGER.debug("RabbitMQ : send message to {} : {}", FanoutExchangeConfig.FANOUT_EXCHANGE, message);
        rabbitMessagingTemplate.convertAndSend(FanoutExchangeConfig.FANOUT_EXCHANGE, "",message);
    }

    @Scheduled(cron = "*/10 * * * * *")
    public void sendWarnMessage()
    {
        String message = UUID.randomUUID().toString();
        LOGGER.debug("RabbitMQ : send message to {} : {}", FanoutExchangeConfig.FANOUT_EXCHANGE, message);
        rabbitMessagingTemplate.convertAndSend(FanoutExchangeConfig.FANOUT_EXCHANGE, "", message);
    }

}
